<template>
  <div class="scroll" ref="wrapper">
    <div class="wrapper">
      <div class="content">
        <slot></slot>
      </div>
    </div>
  </div>
</template>

<script>
import BSscroll from "better-scroll";
export default {
  name: "scroll",
  data() {
    return {
      scroll: null,
    };
  },
  props: {
    probeType: {
      type: Number,
      default: 0,
    },
    pullUpLoad: {
      type: Boolean,
      default: false,
    },
  },
  mounted() {
    this.scroll = new BSscroll(this.$refs.wrapper, {
      probeType: this.probeType,
      mouseWheel: true, //滚轮生效
      pullUpLoad: this.pullUpLoad, //下拉事件，自带probeType:3
      click: true,
    });

    if (this.probeType === 2 || this.probeType === 3) {
      this.scroll.on("scroll", (position) => {
        //  console.log(position)  //打印位置
        this.$emit("scroll", position);
      });
    }
    if (this.pullUpLoad) {
      this.scroll.on("pullingUp", () => {
        //  console.log('加载更多') 
        this.$emit('pullUpload') 
      });
    }
    this.scroll.refresh();
  },

  /* better-scroll返回顶部 scrollTo(x,y,time)*/
  methods: {
    scrollTo(x,y,time) {
      this.scroll && this.scroll.scrollTo(x, y, time);
    },
    refresh() {
      this.scroll && this.scroll.refresh();
    },
    finishPullUp(){
      this.scroll && this.scroll.finishPullUp()
    }
  },

  components: {},
};
</script>

<style  scoped>
</style>
